<template>
  <el-dialog title="角色管理" :visible="showDialog" @close="btnCancel">
    <div style="margin: 15px 0;" />
    <el-checkbox-group v-model="selectRole">
      <el-checkbox v-for="item in list" :key="item.id" :label="item.id">{{ item.name }}</el-checkbox>
    </el-checkbox-group>
    <el-row slot="footer" type="flex" justify="center">
      <el-col :span="12">
        <el-row type="flex" justify="space-around">
          <el-button type="primary" size="small" @click="btnOk">确定</el-button>
          <el-button size="small">取消</el-button>
        </el-row>
      </el-col>
    </el-row>
  </el-dialog>
</template>

<script>
import { getRoleList } from '@/api/setting'
import { getUserDetailById } from '@/api/user'
import { assignRoles } from '@/api/employees'

export default {
  name: 'AssignRole',
  props: {
    showDialog: Boolean,
    userId: [Number, String]
  },
  data() {
    return {
      checkAll: false,
      selectRole: [],
      list: [],
      isIndeterminate: true
    }
  },
  created() {
    this.getList()
  },
  methods: {
    async getList() {
      const { rows } = await getRoleList()
      // console.log(res)
      this.list = rows
    },
    async getCurrentRole(id) {
      const { roleIds } = await getUserDetailById(id)
      console.log(roleIds)
      this.selectRole = roleIds
    },
    btnCancel() {
      this.$emit('update:showDialog', false)
      this.selectRole = []
    },
    async btnOk() {
      await assignRoles({
        id: this.userId,
        roleIds: this.selectRole
      })
      this.$message.success('修改成功')
      this.btnCancel()
    }
  }
}
</script>

<style scoped>

</style>
